package com.peanut.baby.mvp.msg;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.peanut.baby.R;
import com.peanut.baby.model.AppMsg;
import com.peanut.baby.util.TimeUtil;
import com.peanut.devlibrary.widget.pullrecycle.BaseRecyclerAdapter;
import com.peanut.devlibrary.widget.pullrecycle.BaseViewHolder;

import java.util.List;

/**
 * Created by anonymouslystudio on 2017/8/7.
 */

public class AppMsgRecyclerAdapter extends BaseRecyclerAdapter<AppMsg>{
    private OnItemClickListener listener;

    public AppMsgRecyclerAdapter(Context context, List<AppMsg> data) {
        super(context, data);
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        this.listener = listener;
    }

    @Override
    protected void convert(BaseViewHolder holder, final AppMsg item) {
        TextView content = holder.getView(R.id.msg_content);
        TextView time = holder.getView(R.id.msg_time);
        View     readFlag = holder.getView(R.id.msg_read_flag);

        content.setText(item.message);
        time.setText(TimeUtil.getDisplayTimeMillis(item.createTime));

        if(item.readFlag == 1){
            readFlag.setVisibility(View.GONE);
        }else{
            readFlag.setVisibility(View.VISIBLE);
        }

        holder.getView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null){
                    listener.onItemClick(item);
                }
            }
        });

    }

    @Override
    protected int getLayoutId() {
        return R.layout.layout_item_app_msg;
    }

    public interface OnItemClickListener{
        void onItemClick(AppMsg msg);
    }
}
